<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@include file="../../include/import.jsp" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
    <title>call客管理</title>
    <style>
        #pageNoToGo {
            margin-top: 5px;
        }

        th {
            text-align: center;
        }

        .pageConfirm {
            margin-bottom: 5px;
        }
    </style>
    <script type='text/javascript'
            src='${pageContext.request.contextPath}/js/jquery-ui/jquery-ui.min.js'></script>
    <link
            href="${pageContext.request.contextPath}/js/jquery-ui/jquery.multiselect.css"
            rel="stylesheet"/>
    <link
            href="${pageContext.request.contextPath}/js/jquery-ui/jquery-ui.css"
            rel="stylesheet"/>
    <script type='text/javascript'
            src='${pageContext.request.contextPath}/js/jquery-ui/jquery.multiselect.js'></script>
    <link
            href="${ctx }/js/jQuery-File-Upload-9.5.7/css/jquery.fileupload.css"
            type="text/css" rel="stylesheet"/>
</head>
<body>
<br/>

<h2>call客管理</h2>
<br/>
<ul class="nav nav-tabs" id="myTab">
    <li class="active"><a href="#originPhone" onclick="loadOriginPage();">原始号码库</a></li>
    <li><a href="#dialedPhone" onclick="loadDailedListPage();">已拨号码</a></li>
    <li><a href="#workerStatics" onclick="freshWorkerStatics()">任务统计</a></li>
    <li><a href="#caller" onclick="loadCallerPage(1)">call客列表</a></li>
    <li><a href="#setting" onclick="loadPageSetting()">设置</a></li>

</ul>
<div class="tab-content">

    <div class="tab-pane active" id="originPhone">
        <%@include file="./originList.jsp" %>
    </div>

    <div class="tab-pane" id="dialedPhone">
        <%@include file="./callRecordList.jsp" %>
    </div>

    <div class="tab-pane" id="workerStatics">
        <%@include file="./salerStatistic.jsp" %>
    </div>


    <div class="tab-pane" id="caller">
        <%@include file="./callerList.jsp" %>
    </div>
    <div class="tab-pane" id="setting">
        <%@include file="./setting.jsp" %>
    </div>
</div>

<script type="text/javascript">
    $(document).ready(function () {

        activeMenu("callerManage");
        loadAllCaller();
        $('#myTab a').click(function (e) {
            e.preventDefault();
            $(this).tab('show');
        });


        numGroupClickTrigger();
    });

    function bindPageTool(el, page, func) {
        $(el).find("#pageNoTool").html(page.pageNo + "/" + page.totalPages);
        $(el).find("#totalRecords").html(page.totalRecords);
        var firstPage = $(el).find("#firstPage");
        var frontPage = $(el).find("#frontPage");
        var nextPage = $(el).find("#nextPage");
        var lastPage = $(el).find("#lastPage");
        if (page.firstPageNo == page.pageNo || page.pageNo == 0) {
            firstPage.find("a").attr("href", "javascript:void(0)");
            firstPage.attr("class", "active");
        } else {
            firstPage.find("a").attr("href",
                            "javascript:" + func + "(" + page.firstPageNo + ")");
            firstPage.removeClass("active");
        }
        if (page.previousPageNo == page.pageNo || page.previousPageNo == 0
                || page.pageNo == 0) {
            frontPage.find("a").attr("href", "javascript:void(0)");
            frontPage.attr("class", "active");
        } else {
            frontPage.find("a").attr("href",
                            "javascript:" + func + "(" + page.previousPageNo + ")");
            frontPage.removeClass("active");
        }
        if (page.nextPageNo > page.totalPages || page.pageNo == 0) {
            nextPage.find("a").attr("href", "javascript:void(0)");
            nextPage.attr("class", "active");
        } else {
            nextPage.find("a").attr("href",
                            "javascript:" + func + "(" + page.nextPageNo + ")");
            nextPage.removeClass("active");
        }
        if (page.lastPageNo == page.pageNo || page.pageNo == 0) {
            lastPage.find("a").attr("href", "javascript:void(0)");
            lastPage.attr("class", "active");
        } else {
            lastPage.find("a").attr("href",
                            "javascript:" + func + "(" + page.totalPages + ")");
            lastPage.removeClass("active");
        }
    }

    function GetDateStr(AddDayCount) {
        var dd = new Date();
        dd.setDate(dd.getDate() + AddDayCount);//获取AddDayCount天后的日期
        var y = dd.getFullYear();
        var m = (dd.getMonth() + 1) < 10 ? "0" + (dd.getMonth() + 1) : (dd
                .getMonth() + 1);//获取当前月份的日期，不足10补0
        var d = dd.getDate() < 10 ? "0" + dd.getDate() : dd.getDate(); //获取当前几号，不足10补0
        return y + "-" + m + "-" + d;
    }

    function loadAllCaller() {
        reLoadAllCaller0("#dailedQueryCallerId", "#workerStaticsCallerId");
    }

    function reLoadAllCaller0(id1, id2) {

        $(id1).html("");
        $(id2).html("");
        $.ajax({
            type: "get",//使用get方法访问后台
            dataType: "json",//返回json格式的数据
            url: "${ctx }/merchant/caller/allCallers.json",//要访问的后台地址
            success: function (data) {//msg为返回的数据，在这里做数据绑定
                var frow = "<option value='0'>全部</option>";
                $(frow).appendTo(id1);//添加到模板的容器中
                $(frow).appendTo(id2);//添加到模板的容器中
                $.each(data, function (i, n) {
                    var row = "<option value='" + n.id + "'>" + n.name + "</option>";
                    $(row).appendTo(id1);//添加到模板的容器中
                    $(row).appendTo(id2);//添加到模板的容器中
                });

            }
        });
    }

    function freshWorkerStatics() {
        loadPage3(1);
    }

    function deleteBranch(el) {
        if (confirm('确定删除?')) {
            var tr = $(el).parents('tr');
            $(el).parents('tr').remove();
        }
    }

    function editBranch(el) {
        $(el).text("保存");
        $(el).attr("onclick", "saveBranch(this)");
        var el = $(el).parents('tr').find("span");
        el.html($("<input type='text' class='input-small' value='"
                + el.text() + "'  > "));

    }

    function saveBranch(el) {

        $(el).text("修改");
        $(el).attr("onclick", "editBranch(this)");
        var el = $(el).parents('tr');
        el.find("span").html(el.find("input").val());
    }

    /* 	//好像没用了
     function acitiveMe(el) {
     $(el).parents("ul").find("li.active").removeClass();
     $(el).parents("li").attr("class", "active");
     } */

    function arrContainsItem(arr, item) {
        for (var arrItem in arr) {
            if (item == arr[arrItem]) {
                return true;
            }
        }
        return false;
    }
    //点击号码组，切换号码组
    function numGroupClickTrigger() {
        $("ul[name='numGroupNavbar'] li.groupNum").click(function (e) {
            $(this).parents("ul").find("li.active").removeClass("active");
            $(this).addClass("active");
        });
    }

    function resetButton(id, content) {
        $(id).html(content);
        $(id).removeClass("disabled");
    }
    function loadingButton(id) {
        var content = $(id).attr("data-loading-text");
        $(id).html(content);
        $(id).addClass("disabled");
    }
</script>
</body>
</html>
